package com.kevin.demo.service.user.impl;


import com.kevin.demo.annotation.AbleInsertOrUpdateLog;
import com.kevin.demo.annotation.AbleInsertLog;
import com.kevin.demo.annotation.AbleUpdateLog;
import com.kevin.demo.constants.BizEnum;
import com.kevin.demo.entity.user.User;
import com.kevin.demo.framwork.Result;
import com.kevin.demo.service.base.BaseService;
import com.kevin.demo.service.log.BizLogService;
import com.kevin.demo.service.user.UserService;
import com.kevin.demo.vo.input.user.UserFilters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



import java.util.Arrays;

/**
 * @author: e20160504
 * @date: 2018/7/19
 * @desc
 */
@Service
public class UserServiceImpl extends BaseService<User> implements UserService {


    @Autowired
    private BizLogService bizLogService;

    @Override
    @AbleInsertOrUpdateLog(serviceclass = UserServiceImpl.class,handledName = "用户信息")
    public Result insert(User user){
        return super.insert(user);
    }

    @Override
    @AbleInsertOrUpdateLog(serviceclass = UserServiceImpl.class,handledName = "用户信息")
    //@AbleUpdateLog(oprName = OprEnum.UPDATE,serviceclass = UserServiceImpl.class,handleName = "更新用户信息")
    public Result update(User obj) {

        User oldObject = super.selectByKey(obj.getId());
        //记录更新日志
        try {
            bizLogService.insert(oldObject, obj, BizEnum.FGROSS, OprEnum.UPDATE, null,Arrays.asList("username","age"));
        } catch (Exception e) {
            logger.error("毛利率插入日志出错");
            e.printStackTrace();
        }
        return super.update(obj);
    }

    @Override
    public Result list(UserFilters filter) {
        return super.list(filter);
    }

    @Override
    public User selectByKey(Integer id) {
        return super.selectByKey(id);
    }

}
